package org.lex.io;

import java.io.PrintStream;

import javax.swing.JTextArea;

public class ResetSystemStream extends PrintStream {
	private JTextArea outputArea;

	protected ResetSystemStream(PrintStream out, JTextArea outputArea) {
		super(out);
		this.outputArea = outputArea;
	}

	public void write(byte[] buf, int off, int len) {
		try {
			// super.write(buf,off,len);
			outputArea.append(new String(buf, off, len));
		} catch (Exception e) {
		}
	}

	public static void setSystemOutTo(JTextArea outputArea) {
		PrintStream out = new ResetSystemStream(System.out, outputArea);
		System.setOut(out);
	}

	public static void setSystemErrTo(JTextArea outputArea) {
		PrintStream out = new ResetSystemStream(System.out, outputArea);
		System.setErr(out);
	}

	public static void setSystemOutAndErrTo(JTextArea outputArea) {
		PrintStream out = new ResetSystemStream(System.out, outputArea);
		System.setOut(out);
		System.setErr(out);
	}
}
